
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Scanner;
import javax.swing.JOptionPane;
import fit.ActionFixture;
import Controllers.GlobalData;
import Controllers.RequestManager;
import Controllers.GenericToolsForController.RequestMainStatusEnum;
import Controllers.GenericToolsForController.RequestStepStatusEnum;
import Entity.Request;
import Entity.RequestStatusHistory;
import Entity.Status;
import Entity.User;
import Entity.Worker;
import ICM_OCSF.Client;



public class CloseRequest extends ActionFixture
{
	int inspedtorId;
	int requestId;
	List<Request> requestsList;

	public CloseRequest()
	{
		
	}
	 
	//Connect to the Server.
	public void enterToSystem()
	{
		/*
		  in the System we have:
		  initiator  -  id 3
		  2 inspectors shimon1171 - id 62, guyp = id 2.
		  There are 5 request:
			request No 21, here inspector are shimon1171 , the Ststus is: OPEN, REV_REVIEWED_CLOSE.
			request No 22, here inspector are shimon1171 , the Ststus is: OPEN, TST_PASSED.
			request No 23, here inspector are shimon1171 , the Ststus is: OPEN, EXE_PASSED.
			request No 24, here inspector are shimon1171 , the Ststus is: SUSPEND, TST_PASSED.
			request No 25, here inspector are guyp , the Ststus is: OPEN, TST_PASSED
		 */
		
		Request req;
		requestsList = new ArrayList<Request>();
		
		Worker inspector_62,inspector_2;
		inspector_62 = new Worker(1, 62, "shimon", "Arzuan", "icmbraudesys@gmail.com", "0508-1234567", "shimon1171", "2" );
		inspector_2 = new Worker(2, 2, "guy", "peleg", "icmbraudesys@gmail.com", "0508-1234567", "guyp", "2" );
		User initiator = new User(3, "Ron", "Rosesnfeld","icmbraudesys@gmail.com", "0508-1234567", "roon", "Student");		

		//the current worker that log to the system
		GlobalData.worker = inspector_62;
				
		req = new Request();
		req.setRequestId(21);
		req.setInspector(inspector_62);
		req.setInitiator(initiator);
		Status status = new Status(RequestStepStatusEnum.REV_REVIEWED_CLOSE, RequestMainStatusEnum.OPEN); 
		RequestStatusHistory cureentStatus = new RequestStatusHistory(1, status, new Date(), new Date(), null, null, null);
		req.setCurrentStatus(cureentStatus);
	    ArrayList<RequestStatusHistory> history = new ArrayList<RequestStatusHistory>();
		history.add(cureentStatus);
		req.setHistory(history);
		requestsList.add(req);
		
		
		req = new Request();
		req.setRequestId(22);
		req.setInspector(inspector_62);
		req.setInitiator(initiator);
		status = new Status(RequestStepStatusEnum.TST_PASSED, RequestMainStatusEnum.OPEN); 
		cureentStatus = new RequestStatusHistory(2, status, new Date(), new Date(), null, null, null);
		req.setCurrentStatus(cureentStatus);
	    history = new ArrayList<RequestStatusHistory>();
		history.add(cureentStatus);
		req.setHistory(history);
		requestsList.add(req);
		
		
		req = new Request();
		req.setRequestId(23);
		req.setInspector(inspector_62);
		req.setInitiator(initiator);
		status = new Status(RequestStepStatusEnum.EXE_PASSED, RequestMainStatusEnum.OPEN); 
		cureentStatus = new RequestStatusHistory(3, status, new Date(), new Date(), null, null, null);
		req.setCurrentStatus(cureentStatus);
	    history = new ArrayList<RequestStatusHistory>();
		history.add(cureentStatus);
		req.setHistory(history);
		requestsList.add(req);
		
		
		req = new Request();
		req.setRequestId(24);
		req.setInspector(inspector_62);
		req.setInitiator(initiator);
		status = new Status(RequestStepStatusEnum.TST_PASSED, RequestMainStatusEnum.SUSPEND); 
		cureentStatus = new RequestStatusHistory(4, status, new Date(), new Date(), null, null, null);
		req.setCurrentStatus(cureentStatus);
	    history = new ArrayList<RequestStatusHistory>();
		history.add(cureentStatus);
		req.setHistory(history);
		requestsList.add(req);	
		
		
		req = new Request();
		req.setRequestId(25);
		req.setInspector(inspector_2);
		req.setInitiator(initiator);
		status = new Status(RequestStepStatusEnum.TST_PASSED, RequestMainStatusEnum.OPEN); 
		cureentStatus = new RequestStatusHistory(4, status, new Date(), new Date(), null, null, null);
		req.setCurrentStatus(cureentStatus);
	    history = new ArrayList<RequestStatusHistory>();
		history.add(cureentStatus);
		req.setHistory(history);
		requestsList.add(req);
		
		
	}
	
	
	public void requestNumber(int number)
	{
		this.requestId = number;
	}
	
	public void inspectorId(int number)
	{
		this.inspedtorId = number;
	}
	public boolean closeRequest()
	{
		for(Request req : requestsList)
		     if(req.getRequestId() == requestId)
					return req.close(0);
		return false;
	}
}
